package com.fengmi.goods.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fengmi.comm.ResultVO;
import com.fengmi.goods.MallGoodsSku;
import com.fengmi.goods.mapper.MallGoodsSkuMapper;
import com.fengmi.goods.service.IMallGoodsSkuService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author sujie
 * @since 2022-11-26
 */
@Service
public class MallGoodsSkuServiceImpl extends ServiceImpl<MallGoodsSkuMapper, MallGoodsSku> implements IMallGoodsSkuService {

    @Override
    public ResultVO kcc(Integer skuId, Integer buyNum) {
        MallGoodsSku mallGoodsSku = this.baseMapper.selectById(skuId);
        if(mallGoodsSku==null){
            return new ResultVO("1001","扣库存失败",null);
        }
        mallGoodsSku.setSkuStock(mallGoodsSku.getSkuStock()-buyNum);
        this.baseMapper.updateById(mallGoodsSku);
        return  new ResultVO("1000","扣库存成功",null);
    }
}
